package com.ibm.jdg2e.editor.jfacetext.sqleditor;
/*
 * "The Java Developer's Guide to Eclipse"
 *   by D'Anjou, Fairbrother, Kehn, Kellerman, McCarthy
 * 
 * (C) Copyright International Business Machines Corporation, 2003, 2004. 
 * All Rights Reserved.
 * 
 * Code or samples provided herein are provided without warranty of any kind.
 */
import java.util.MissingResourceException;
import java.util.ResourceBundle;

import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;

import com.ibm.jdg2e.editor.jfacetext.sqleditor.sql.SQLPartitionScanner;
import com.ibm.jdg2e.editor.sqleditor.utils.ColorProvider;

/**
 * The main plug-in class.
 */
public class SQLEditorPlugin extends AbstractUIPlugin {
  //The shared instance.
  private static SQLEditorPlugin plugin;
  //Resource bundle.
  private ResourceBundle resourceBundle;

  ColorProvider colorProvider;
  private SQLPartitionScanner fPartitionScanner;
	public final static String SQL_PARTITIONING= "__sql_partitioning";   //$NON-NLS-1$

  /**
   * The constructor.
   */
  public SQLEditorPlugin() {
    super();
    plugin = this;
    try {
      resourceBundle = ResourceBundle
          .getBundle("com.ibm.jdg2e.editor.jfacetext.sqleditor.SQLEditorPluginResources");
    } catch (MissingResourceException x) {
      resourceBundle = null;
    }
    colorProvider = new ColorProvider();

  }

  /**
   * Returns the shared instance of the Plugin.
   */
  public static SQLEditorPlugin getDefault() {
    return plugin;
  }

  /**
   * Returns the workspace instance.
   */
  public static IWorkspace getWorkspace() {
    return ResourcesPlugin.getWorkspace();
  }

  /**
   * Returns the string from the plugin's resource bundle, or 'key' if not
   * found.
   */
  public static String getResourceString(String key) {
    ResourceBundle bundle = SQLEditorPlugin.getDefault()
        .getResourceBundle();
    try {
      return bundle.getString(key);
    } catch (MissingResourceException e) {
      return key;
    }
  }

  /**
   * Returns the plugin's resource bundle,
   */
  public ResourceBundle getResourceBundle() {
    return resourceBundle;
  }
  public void disposeColorProvider() {
    colorProvider.dispose();

  }
	/**
	 * This method is called upon plug-in activation
	 */
	public void start(BundleContext context) throws Exception {
		super.start(context);
	}

	/**
	 * This method is called when the plug-in is stopped
	 */
	public void stop(BundleContext context) throws Exception {
		super.stop(context);
	}
  /**
   * Returns the colorProvider.
   * 
   * @return ColorProvider
   */
  public ColorProvider getColorProvider() {
    return colorProvider;
  }
	/**
	 * Return a scanner for creating java partitions.
	 */
	 public SQLPartitionScanner getSQLPartitionScanner() {
		if (fPartitionScanner == null)
			fPartitionScanner= new SQLPartitionScanner();
		return fPartitionScanner;
	}
}